package com.aldobucchi.x.mx.controls.sliderClasses.Slider
{
	
	import com.aldobucchi.core.dependency.DependencySpec;
	import com.aldobucchi.core.dependency.MXMLObjectWithDependenciesBase;
	import com.aldobucchi.utils.IOperator;
	
	import flash.display.DisplayObject;
	
	import mx.controls.sliderClasses.Slider;


	public class SliderZoomingConnector extends MXMLObjectWithDependenciesBase
	{
		
		private var sliderSpec:DependencySpec = new DependencySpec( "slider", "*" );
		[Bindable("sliderChanged")]
		public function get slider( ):Slider
		{
			return dh.getDependencyValue( sliderSpec );
		}
		public function set slider( v:Slider ):void
		{
			dh.setDependencyValue( sliderSpec, v );
		}
		



		private var targetSpec:DependencySpec = new DependencySpec( "target", "*" );
		[Bindable("targetChanged")]		
		public function get target( ):DisplayObject
		{
			return dh.getDependencyValue( targetSpec );
		}
		public function set target( v:DisplayObject ):void
		{
			dh.setDependencyValue( targetSpec, v );
		}
		
		
		
		
		private var minScaleSpec:DependencySpec = new DependencySpec( "minScale", "*" );
		[Bindable("minScaleChanged")]		
		public function get minScale( ):Number
		{
			return dh.getDependencyValue( minScaleSpec );
		}
		public function set minScale( v:Number ):void
		{
			dh.setDependencyValue( minScaleSpec, v );
		}		
		
		

		private var maxScaleSpec:DependencySpec = new DependencySpec( "maxScale", "*" );
		[Bindable("maxScaleChanged")]		
		public function get maxScale( ):Number
		{
			return dh.getDependencyValue( maxScaleSpec );
		}
		public function set maxScale( v:Number ):void
		{
			dh.setDependencyValue( maxScaleSpec, v );
		}		
				
		
		
		
		/**
		 * 
		 * Will modify the target's x and y props to keep it centered in its parent
		 * ( assumes the focus point is the center of the parent )
		 * 
		 */		
		public var autoCenterInParent:Boolean = true;
		
		
		
		
		
		
		private var op:IOperator;
		
		
		override protected function dependenciesUpdated( ):void
		{
		
			if ( op )
			{
				op.dispose( );		
				op = null;
			}
			
			
			if ( target && slider && minScale && maxScale )
			{
				op = new SliderZoomingOp( slider, target, minScale, maxScale, autoCenterInParent );	
			}
		}
		
		
		
		
	}
}